package housekeeping.controller;

import housekeeping.pojo.Serve;
import housekeeping.service.ServeService;
import housekeeping.util.ServerResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ServiceController
 * Description:
 *
 * @Author 迷藏
 * @Create 2025/7/7 21:51
 * @Version 1.0
 */
@RestController
@CrossOrigin
@Tag(name = "服务项目管理")
public class ServiceController {
    @Autowired
    private ServeService serveService;

    @GetMapping("/service/list")
    @Operation(summary = "显示所有服务")
    public ServerResult<List<Serve>> getService() {
        List<Serve> list = serveService.getServices();
        return ServerResult.ok(list);
    }

    @DeleteMapping("/service/delete/{id}")
    @Operation(summary = "删除服务")
    private ServerResult<Void> deleteService(@PathVariable("id") Integer id){
        serveService.deleteService(id);
        return ServerResult.ok();
    }
    @PostMapping("/service/add")
    @Operation(summary = "添加服务")
    private ServerResult<Void> addService(@RequestBody Serve service){
        serveService.insertService(service);
        return ServerResult.ok();
    }

    @PutMapping("/service/update")
    @Operation(summary = "修改服务")
    private ServerResult<Void> updateService(@RequestBody Serve service){
        serveService.updateService(service);
        return ServerResult.ok();
    }
}
